package com.lrj.mysecurity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lrj.mysecurity.dao.RolePermissionDao;
import com.lrj.mysecurity.entity.Permission;
import com.lrj.mysecurity.entity.RolePermission;
import com.lrj.mysecurity.entity.RolePermissionConstant;
import com.lrj.mysecurity.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RolePermissionServiceImpl implements RolePermissionService {
    @Autowired
    private RolePermissionDao rolePermissionDao;

    @Override
    public List<Long> getPermissionIdListByRoleList(List<Long> roleList) {
        if (roleList != null && roleList.size() > 0) {
            QueryWrapper<RolePermission> queryWrapper = new QueryWrapper<>();
            queryWrapper.in(RolePermissionConstant.COLUMN_ROLE_ID, roleList);
            List<RolePermission> rolePermissionList = rolePermissionDao.selectList(queryWrapper);
            List<Long> permissionIdList = rolePermissionList.stream().map(rolePermission -> rolePermission.getPermissionId()).collect(Collectors.toList());
            return permissionIdList;
        }

        return null;
    }
}
